//
//  MainViewController.swift
//  新浪微博(day01练习)
//
//  Created by KeY on 16/1/11.
//  Copyright © 2016年 KeY. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    @objc private func plusBtnDidClick() {
    
        print(__FUNCTION__)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let mainTabbar = MainTabbar()
        setValue(mainTabbar, forKey: "tabBar")
        mainTabbar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
        addChildViewControllers()
        // Do any additional setup after loading the view.
    }
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(ProfileTableViewController(), imageName: "tabbar_profile", title: "我")
}
    
    private func addChildViewController(vc: UIViewController,imageName: String,title: String) {
        //设置tabBarIrem的图片
        vc.tabBarItem.image = UIImage(named:imageName)
        //设置选中状态下的图片颜色,在闭包中要用self调用属性
        self.tabBar.tintColor = UIColor.orangeColor()
        //设置title
        vc.title = title
        //创建一个导航控制器
        let nav = UINavigationController(rootViewController: vc)
        //添加子视图控制器
        addChildViewController(nav)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
